package com.wnhz.work.yz.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.wnhz.work.yz.MyApplication;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.bean.GoodsListBean;

import java.text.DecimalFormat;
import java.util.List;

/**
 * Created by admin on 2016/12/10.
 */
public class BathAdapter extends BaseAdapter {
    private Context context;
    private List<GoodsListBean> beanList;

    public BathAdapter(Context context, List<GoodsListBean> beanList) {
        this.context = context;
        this.beanList = beanList;
    }

    @Override
    public int getCount() {
        return beanList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        BathViewHolder viewHolder = new BathViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.bath_item, null);
            viewHolder.iv_img = (ImageView) convertView.findViewById(R.id.iv_img);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.tv_number = (TextView) convertView.findViewById(R.id.tv_number);
            viewHolder.tv_price = (TextView) convertView.findViewById(R.id.tv_price);
            viewHolder.tv_message = (TextView) convertView.findViewById(R.id.tv_message);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (BathViewHolder) convertView.getTag();
        }
       // x.image().bind(viewHolder.iv_img, beanList.get(position).getGoodsImg());
        ImageLoader.getInstance().displayImage(beanList.get(position).getGoodsImg(),viewHolder.iv_img);
        viewHolder.tv_name.setText(beanList.get(position).getGoodsName());
        viewHolder.tv_message.setText(beanList.get(position).getGoodsContent());
        viewHolder.tv_number.setText(" 库存" + beanList.get(position).getStore() + "件");
        DecimalFormat df = new DecimalFormat("######0.00");
//        if (MyApplication.getInstance().getUserBean() != null)
//        Log.e("----", MyApplication.getInstance().getUserBean().getRatio() + "");
        /*try {
            viewHolder.tv_price.setText("¥ " + df.format(Double.parseDouble(beanList.get(position).getPrice()) * Double.parseDouble(MyApplication.getInstance().getUserBean().getRatio().toString())));
        } catch (Exception e) {*/
            viewHolder.tv_price.setText("¥ " + df.format(Double.parseDouble(beanList.get(position).getPrice())));
//        }
        return convertView;
    }

    class BathViewHolder {
        ImageView iv_img;
        TextView tv_name;
        TextView tv_number;
        TextView tv_price;
        TextView tv_message;
    }
}
